package org.example.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.commonapi.domain.CollectPractice;
import org.example.commonapi.dto.PageInfo;
import org.example.commonapi.dto.PracticeInfoDto;
import org.example.user.service.CollectPracticeService;
import org.example.commonapi.mapper.CollectPracticeMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

/**
* @author XieNoDesire
* @description 针对表【collect_practice(收藏表)】的数据库操作Service实现
* @createDate 2024-06-02 21:26:27
*/
@Service
public class CollectPracticeServiceImpl extends ServiceImpl<CollectPracticeMapper, CollectPractice>
    implements CollectPracticeService{

    @Resource
    CollectPracticeMapper collectPracticeMapper;
    /**
     * 查询收藏题目列表
     * @param id
     * @return
     */
    @Override
    public List<PracticeInfoDto> collectPracticeIdList(Integer difficulty, Integer type, String name, String subject,Long id) {
        return collectPracticeMapper.collectPracticeIdList(difficulty,type,name,subject,id);
    }


    /**
     * 单个删除收藏练习
     * @param practiceId
     * @param studentId
     */
    @Override
    public void deleteCollectPractice(Long practiceId, Long studentId) {
        LambdaQueryWrapper<CollectPractice> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CollectPractice::getPracticeId,practiceId).eq(CollectPractice::getUserId,studentId);
        collectPracticeMapper.delete(queryWrapper);
    }

    /**
     * 分页查询
     * @param pageNum
     * @param pageSize
     * @param difficulty
     * @param type
     * @param name
     * @param subject
     * @param id
     * @return
     */
    @Override
    public PageInfo collectPracticeList(Integer pageNum, Integer pageSize, Integer difficulty, Integer type, String name, String subject, Long id) {
//        分页条件
        Page<PracticeInfoDto> page=new Page<>(pageNum,pageSize);
//        分页查询语句
        IPage<PracticeInfoDto>  pages=collectPracticeMapper.collectPracticeList(page,difficulty,type,name,subject,id);
        return new PageInfo(pages);
    }


}




